package CollectionsDay02;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class SortListDemo3 {
    public static void main(String[] args) {
        List<Point> list = new ArrayList<Point>();
        list.add(new Point(5,8));
        list.add(new Point(13,42));
        list.add(new Point(43,43));
        list.add(new Point(27,85));
        list.add(new Point(25,34));
        System.out.println(list);
        /*Collections.sort(list, new Comparator<CollectionsDay02.Point>() {
            public int compare(CollectionsDay02.Point o1, CollectionsDay02.Point o2) {
                int len1 = o1.getX()* o1.getY()+ o1.getX()* o1.getY();
                int len2 = o2.getX()* o2.getY()+ o2.getX()* o2.getY();
//                return len2-len1;//升序
//                return len1-len2;//降序

//                return o1.getX()- o2.getX();//按x坐标升序
                return o2.getY()- o1.getY();//按y坐标降序
            }
        });
        System.out.println(list);*/

        list.sort(new Comparator<Point>() {
            public int compare(Point o1, Point o2) {
                int len1 = o1.getX()* o1.getY()+ o1.getX()* o1.getY();
                int len2 = o2.getX()* o2.getY()+ o2.getX()* o2.getY();
                return len1-len2;
            }
        });
        System.out.println(list);
    }
}
